package review;

/**
 * Description:
 *
 * @Author:
 * @Date: 2024/7/20 15:38
 */
public class MyInterrupt1 extends Thread{
    volatile boolean flag = false; // 线程执行的退出标记
    @Override
    public void run() {
        while(!flag){
            System.out.println("MyThread...run...");
            try {
                Thread.sleep(3000L);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
        System.out.println("Thread exiting...");
    }

    public static void main(String[] args) throws InterruptedException {
        // 创建MyInterrupt1对象
        MyInterrupt1 t1 = new MyInterrupt1();
        t1.start();

        // 主线程休眠6秒
        Thread.sleep(6000L);

        // 更改标记为true
        t1.flag = true;
        System.out.println("flag is true");

    }
}
